package com.bz.sso.controller.fallback;

import com.bz.dto.CartDto;
import com.bz.pojo.TbUser;
import com.bz.sso.feign.CommonRedisFeignClient;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * CommonContent 服务器 - openfeign 降级处理
 * 注意：实现服务降级后，db操作失败，将不会抛出异常，也就是说不会抛出异常，事务就不会生效，这时候可以手动判断抛出异常
 */
@Component
public class CommonRedisFeignClientFallbackFactory implements FallbackFactory<CommonRedisFeignClient> {

    @Override
    public CommonRedisFeignClient create(Throwable throwable) {
        return new CommonRedisFeignClient() {
            @Override
            public void insertUser(TbUser tbUser, String userToken) {

            }

            @Override
            public void logout(String userToken) {

            }

            @Override
            public TbUser checkUserToken(String userToken) {
                return null;
            }

            @Override
            public CartDto selectCartByUserId(Long userId) {
                return null;
            }

            @Override
            public void insertCart(CartDto cartDto) {

            }
        };
    }
}
